import React from "react";
import frame from '../../../style/frame.less';

class Trow extends React.Component {

    constructor(props) {
        super(props);
    }

    rule = (key) => (
        key.indexOf('_') > -1 ? key.replace(/_/g, "").toUpperCase() : key.toUpperCase()
    );

    resetColumn() {
        const {data} = this.props;
        let _data = {};

        //分析 data 数据，将KEY值标准化处理
        Object.keys(data).map(key => {
            _data[this.rule(key)] = this.props.data[key];
        });

        //分析 title 数据，提取title字段当做key值,依次按照顺序取出
        return this.props.title.map((item) => {
            const key = this.rule(item.field);
            if (item.render != undefined && item.render != null) {//如果title 里面包含了 render 优先使用render
                return item.render(_data[key], data);
            } else {
                return _data[key]
            }
        });
    }

    render() {
        return (
            <tr>
                {this.resetColumn().map((value, index) => {
                    return (
                        <td key={index}>{value}</td>
                    )
                })}
            </tr>
        )
    }
}

export default Trow
